Skip to content

Fix transport session id mismatch with sessionId #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CrazyHZM
Copy link
Contributor

@CrazyHZM CrazyHZM commented Apr 20, 2025

Motivation and Context

Fix #168

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Signed-off-by: JermaineHua <crazyhzm@apache.org>
@yu199195
Copy link

good job,I also found this problem, now get the correct seesion, not inside the mcp session, but inside the transport~

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the proposal! I agree we have a mismatch and we need a way to provide the session id to both the transport and the session objects. I would propose that the McpServerSession.Factory expose a new method, generateId which can be fed into both of these objects. Would you like to apply such a change?

@tzolov tzolov added this to the 0.10.0 milestone May 7, 2025
@tzolov tzolov added the bug Something isn't working label May 7, 2025
@CrazyHZM
Copy link
Contributor Author

CrazyHZM commented May 9, 2025

Thank you for the proposal! I agree we have a mismatch and we need a way to provide the session id to both the transport and the session objects. I would propose that the McpServerSession.Factory expose a new method, generateId which can be fed into both of these objects. Would you like to apply such a change?

Yes, I'll make some revisions to this part.

CrazyHZM added 3 commits May 9, 2025 22:21
Signed-off-by: JermaineHua <crazyhzm@apache.org>
# Conflicts:
#	mcp/src/main/java/io/modelcontextprotocol/server/McpAsyncServer.java
Signed-off-by: JermaineHua <crazyhzm@apache.org>
@CrazyHZM CrazyHZM requested a review from chemicL May 9, 2025 14:27
@tzolov tzolov modified the milestones: 0.10.0, 0.11.0 May 12, 2025
Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work on this. It is almost ready, a few nitpicks about imports.
As a next step we should unify the way the server transports log and include the session id everywhere. But please don't create a PR for it just yet.
@tzolov in 0.11.0 release notes we need to highlight that McpServerSession.Factory went through a breaking change impacting custom transport implementors, not end users per se.

@@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.Map;
import java.util.UUID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this import should be removed

@@ -247,7 +247,7 @@ private ServerResponse handleSseConnection(ServerRequest request) {
return ServerResponse.status(HttpStatus.SERVICE_UNAVAILABLE).body("Server is shutting down");
}

String sessionId = UUID.randomUUID().toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the import too.

@@ -208,7 +208,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
response.setHeader("Connection", "keep-alive");
response.setHeader("Access-Control-Allow-Origin", "*");

String sessionId = UUID.randomUUID().toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the import.

@@ -12,6 +12,7 @@
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary import.

@@ -16,6 +16,7 @@
package io.modelcontextprotocol;

import java.util.Map;
import java.util.UUID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be unused

@@ -10,6 +10,7 @@
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.UUID;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] mvc transport session id mismatch with sessionId
4 participants